
package py.com.erpone.session.dm.list;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import py.com.erpone.entity.dm.Contacto;
import py.com.erpone.entity.dm.Presentacion;
import py.com.erpone.entity.dm.Proveedor;

@Stateless
@LocalBean
@Named
public class ProveedorList {
	
	@PersistenceContext
	private EntityManager em;
	
	
	@SuppressWarnings("unchecked")
	public List<Proveedor> findAllWithLocalization(){
		List<Proveedor> result=(List<Proveedor>)em.createNamedQuery("proveedorProcedencia.all").getResultList();
		return result;
	}
	@SuppressWarnings("unchecked")
	public List<Proveedor> findAll(){
		List<Proveedor> result=(List<Proveedor>)em.createNamedQuery("proveedor.all").getResultList();
		return result;
	} 
	
	public Proveedor findById(Long id){
		return em.find(Proveedor.class, id);
	}
	
	public List<Contacto> findAllContactos(long id){		
		
		/*		return (List<Presentacion>) em.createNamedQuery("Presentacion.presentaciones")
		                .setParameter("id", id)
		                .getResultList();*/
				String sql = " select p.* " +
							 " from proveedor b " +
							 " join contacto p on b.id = p.id" +
							 " where b.id = ? " +
							 " order by b.id";
				
				Query query = em.createNativeQuery(sql, Contacto.class);
				query.setParameter(1, id);
				List<Contacto> result = query.getResultList();
				return result;
			} 
	
}
